<template>
  <!-- <el-container class="home-container"> -->
    <!-- 侧边栏 -->
    <!-- <el-aside width="200px">KinPaySaaS</el-aside> -->
    <!-- 页面主体 -->
    <!-- <el-container> -->
      <!-- 头部区域 -->
      <!-- <el-header>Header</el-header> -->
      <!-- 右侧主体 -->
      <!-- <el-main>Main</el-main> -->
    <!-- </el-container> -->
  <!-- </el-container> -->


  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="">
        <span>安徽大学理工学院</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="asideWidth">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 -->
        <el-menu
          background-color="#20222A"
          text-color="#BCBDBF"
          active-text-color="#409eff"
          :unique-opened="true"
          :collapse-transition="false"
          :collapse="isCollapse"
          :router="true"
          :default-active="navActive"
          >
          <!-- 导航一区域 -->
          <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
            <!-- 导航一 -->
            <template slot="title">
              <i :class="iconsObj[125]"></i>
              <span>{{item.authName}}</span>
            </template>
            <!-- 导航一子菜单 -->
            <el-menu-item @click="saveNavState('/'+subItem.path)" :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <template slot="title">{{subItem.authName}}</template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return{
      menulist: [
        {
            "id": 101,
            "authName": "空调管理",
            "path": null,
            "children": [
                {
                    "id": 104,
                    "authName": "空调列表",
                    "path": "users",
                    "children": []
                },
                {
                    "id": 105,
                    "authName": "测试界面",
                    "path": "test",
                    "children": []
                }
            ]
        }
      ],
      iconsObj: {
        '125':'el-icon-s-custom',
        // '103':'el-icon-s-check',
        // '101':'el-icon-s-goods',
        // '102':'el-icon-s-order',
        // '145':'el-icon-s-data'
      },
      // 是否折叠
      isCollapse: false,
      asideWidth: '200px',
      //当前激活二级菜单
      navActive:''
    }
  },
  created() {
    // this.getMenuList()
    this.navActive = window.sessionStorage.getItem('active')
  },
  methods: {
    logout () {
      // 清空token
      window.sessionStorage.clear()
      // 编程式导航到login
      this.$router.push('/login')
    },
    // 获取所有菜单
    // async getMenuList() {
    //   const  {data:res} = await this.$http.get('menus')
    //   if(res.meta.status !== 200) return this.$message.error(res.meta.msg)
    //   this.menulist = res.data
    //   // console.log(res)
    //   // console.log(this.menulist)
    // },
    // 菜单的折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {
        this.asideWidth = '64px'
      }else {
        this.asideWidth = '200px'
      }
    },
    // 保存二级菜单激活状态
    saveNavState(active) {
      window.sessionStorage.setItem('active', active)
      this.navActive = active
    }
  }
}
</script>

<style lang="less" scoped="scoped">
  .home-container{
    height: 100%;
  }
  .el-header, .el-footer {
    background-color: #393D49;
    color: #BCBDBF;
    // text-align: center;
    // line-height: 60px;
    display: flex;
    justify-content: space-between;
    padding-left: 5;
    align-items: center;
    font-size: 20px;
    > div {
      display: flex;
      align-items: center;
      span{
        margin-left: 15px;
      }
    }
  }
  .el-aside {
    background-color: #20222A;
    color: #BCBDBF;
    // text-align: center;
    // line-height: 200px;
    .el-menu {
      border-right: none;
    }
  }

  .el-main {
    background-color: #F2F2F2;
    color: #000;
    // text-align: center;
    // line-height: 160px;
  }
  .el-header img {
    width: 45px;
  }
  .toggle-button {
    background-color: #4a5064;
    text-align: center;
    font-size: 10px;
    height: 24px;
    line-height: 24px;
    color: #BCBDBF ;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>
